-- revive_skill
-- created by shuzy
-- 死亡后回复血量N%，并触发技能

return {
    apply = function(prop, baseValue)
        -- 千分比
        return math.modf(baseValue * prop[3] / 1000);
    end,

    -- 死亡触发
    trigger = function(who, prop, arg)
        if who.type ~= OBJECT_TYPE_USER then
            return false;
        end

        -- 是否首次复活
        local times = DungeonM.getDungeonMixedField("revive_skill_times");
        if times ~= nil and times > 0 then
            return false;
        end

        DungeonM.setDungeonMixedField("revive_skill_times", 1);

        local p = prop[3];
        local maxHp = who:getMaxHp();
        local hp = math.modf(maxHp * p / 1000);

        -- 设置血量
        who:addAttrib("hp", hp - who:queryAttrib("hp"), "revive_equip");
 
        -- 触发技能
        local skillId = tonumber(prop[2]);
        local round = CombatM.getRound();
        SkillM.apply(who, who, skillId, round);
        EventMgr.fire(event.PLAYER_MOVE, -1);

        return who:getHp() > 0;
    end,

    desc = function(prop)
        local row = PropM.getRow(prop[1]);
        local desc = row.desc;

        local v = math.modf( prop[3] / 10);
        desc = string.gsub(desc, "{1}", v);
        
        local skillName = SkillM.query(tonumber(prop[2]), "name");
        desc = string.gsub(desc, "{0}", skillName);

        return desc;
    end,

    record = function(target, prop, path)
        return false;
    end
};
